// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Matrix2Test.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Test.Robotics.Numerics
{
    using System;

    using Microsoft.Robotics.Numerics;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Unit tests for the Matrix3 class
    /// </summary>
    [TestClass]
    public class Matrix2Test
    {
        /// <summary>
        /// Test the Matrix2 constructor classes
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Matrix2ValueConstructor()
        {
            Matrix2 m = new Matrix2(1.5);
            Assert.IsTrue(
                m.M00 == 1.5
                && m.M01 == 1.5
                && m.M10 == 1.5
                && m.M11 == 1.5,
                "Matrix2 Constructor test failed");

            Matrix2 m2 = new Matrix2(m);
            Assert.IsTrue(
               m2.M00 == 1.5
               && m2.M01 == 1.5
               && m2.M10 == 1.5
               && m2.M11 == 1.5,
               "Matrix2 Constructor test failed");

            Matrix2 m3 = new Matrix2(0, 1, 2, 3);
            Assert.IsTrue(
               m3.M00 == 0
               && m3.M01 == 1
               && m3.M10 == 2
               && m3.M11 == 3,
               "Matrix2 Constructor test failed");
        }

        /// <summary>
        /// Test the Matrix2 transpose 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Matrix2TranposeTest()
        {
            Matrix2 m = new Matrix2(0, 1, 2, 3);
            Matrix2 m2 = Matrix2.Transpose(m);
            Assert.IsTrue(
              m2.M00 == 0
              && m2.M01 == 2
              && m2.M10 == 1
              && m2.M11 == 3,
              "Matrix2 Tranpose test failed");
        }

        /// <summary>
        /// Test the Matrix2 inverse test 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Matrix2InverseTest()
        {
            Matrix2 m = new Matrix2(0, 1, 2, 3);
           
            Assert.AreEqual(Matrix2.Identity(), m * Matrix2.Inverse(m), "Matrix2 Inverse test failed");
        }

        /// <summary>
        /// Test the Matrix2 set test 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Matrix2SetGetTest()
        {
            Matrix2 m = new Matrix2();
            m.M00 = 1;
            m.M01 = 2;
            m.M10 = 3;
            m.M11 = 4;

            Assert.IsTrue(
              m.M00 == 1
              && m.M01 == 2
              && m.M10 == 3
              && m.M11 == 4,
              "Matrix2 SetGet test failed");
        }

        /// <summary>
        /// Test the Matrix2 addition test 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Matrix2AdditionTest()
        {
            Matrix2 m = new Matrix2(1);
            Matrix2 m2 = new Matrix2(1, 2, 3, 4);
            Matrix2 m3 = m + m2;
 
            Assert.IsTrue(
              m3.M00 == 2
              && m3.M01 == 3
              && m3.M10 == 4
              && m3.M11 == 5,
              "Matrix2 Addition test failed");
        }

        /// <summary>
        /// Test the Matrix2 subtraction test 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Matrix2SubtractionTest()
        {
            Matrix2 m = new Matrix2(1);
            Matrix2 m2 = new Matrix2(1, 2, 3, 4);
            Matrix2 m3 = m2 - m;

            Assert.IsTrue(
              m3.M00 == 0
              && m3.M01 == 1
              && m3.M10 == 2
              && m3.M11 == 3,
              "Matrix2 Subtraction test failed");
        }

        /// <summary>
        /// Test the Matrix2 subtraction test 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Matrix2MultiplyTest()
        {
            Matrix2 m = new Matrix2(1);
            Matrix2 m2 = new Matrix2(1, 2, 3, 4);
            Matrix2 m3 = m * m2;

            Assert.IsTrue(
              m3.M00 == 4
              && m3.M01 == 6
              && m3.M10 == 4
              && m3.M11 == 6,
              "Matrix2 Multiply test failed");
        }

        /// <summary>
        /// Test the Matrix2 subtraction test 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Matrix2IdentityTest()
        {
            Matrix2 m = Matrix2.Identity();
  
            Assert.IsTrue(
              m.M00 == 1
              && m.M01 == 0
              && m.M10 == 0
              && m.M11 == 1,
              "Matrix2 Identity test failed");
        }
    }
}
